import { message } from 'ant-design-vue';
import type { DtoFailMode4requirementList} from "./type.ts";
import {ref} from "vue";

export const expandIndex=ref(0);

// 添加失效模式
export const addFailMode = (failModes: DtoFailMode4requirementList[]) => {
    const lastFailMode = failModes[failModes.length - 1];
    if (lastFailMode && lastFailMode.fmDesc?.trim() !== '') {
        failModes.push({
            fmId:undefined,
            fmDesc:'',
            ctrlPlans:[{}],
        });
    } else {
        message.warning('请先填写当前痛点描述');
    }
};

// 展开失效模式
export const expandFailMode = (index: number) => {
    expandIndex.value=index;
};

// 移除失效模式
export const removeFailMode = (failModes: DtoFailMode4requirementList[], index: number) => {
    if (failModes.length > 1) {
        failModes.splice(index, 1);
    } else {
        message.warning('至少需要保留一个痛点');
    }
};
